﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Core.h".
//-------------------------------------------------------------------

#ifndef _UXS_ALLOCATOR_TYPE_H
#define _UXS_ALLOCATOR_TYPE_H

#pragma once

#include "../Types/MemFunc.h"
#include "../Types/Utils.h"

namespace UX_STL
{
namespace UXTypes
{

	//
	// Allocator
	//

	template <typename T>
	struct TAllocator
	{
		static T * Allocate (usize uSize)
		{
			return (T*)_alloc( sizeof(T) * uSize );
		}

		static void Deallocate (T *&pMem)
		{
			_dealloc( reinterpret_cast< void *&>( pMem ) );
		}
	};



	//
	// Aligned Allocator
	//

	template <typename T, usize Align = 16>
	struct TAlignedAllocator
	{
		static T * Allocate (usize uSize)
		{
			return (T*)_aligned_alloc( sizeof(T) * uSize, Align );
		}

		static void Deallocate (T *&pMem)
		{
			_aligned_dealloc( reinterpret_cast< void *&>( pMem ) );
		}
	};

//-------------------------------------------------------------------

}	// UXTypes
}	// UX_STL

#endif	// _UXS_ALLOCATOR_TYPE_H